#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_HeatNetAssistClient.h"
#include <QtNetWork/QTcpSocket>
#include <QSettings>
#include <QSystemTrayIcon>
#include <thread>
#include <atomic>
#include <vector>
#include <QSoundEffect>

class HeatNetAssistClient : public QMainWindow
{
    Q_OBJECT

public:
    HeatNetAssistClient(QWidget *parent = nullptr);
    ~HeatNetAssistClient();
public:
    bool StartMonitor();

    bool StopMonitor();

    bool IsTcpConnected();
private:
    bool CheckServerInfo();

    bool StartTcpConnect();
    bool StopTcpConnect();

    void DealAlarmInfo(QString strState, QString strAlarmTime, int iAlarmType);

    void ShowMainWindow();
protected:
    virtual void closeEvent(QCloseEvent* event);
    virtual void resizeEvent(QResizeEvent* event);
    virtual void changeEvent(QEvent*);
Q_SIGNALS:
    void SignalConnectFailed();
private slots:
    void OnTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
    void OnActionSetting();
    void OnActionConfirm();
    void OnActionMonitor(bool bChecked);
    void OnActionMonitorStatus(bool bChecked);
    void OnActionQuit();
    void OnConnectFailed();
    void OnConnected();
    void OnDisconnected();
    void OnReadyRead();
    void OnStateChanged(QAbstractSocket::SocketState);
    void OnSocketError(QAbstractSocket::SocketError);
private:
    Ui::HeatNetAssistClient ui;
    QTcpSocket* cltsocket;
    QSystemTrayIcon* systemTrayIcon;
    QSettings* settings;

    std::thread threadCltCnnt;
    int cltstopflag_;

    std::vector<QString> vctAlarmName;
    QSoundEffect    soundPlayer;
};
